#include "ODN_LogMgr.h"

#include <iostream>

namespace ouden {

template<>
ODN_DLLACCESS CLogMgr* CSingleton<CLogMgr>::m_pInstance = 0;

CLogMgr::CLogMgr()
{
	//ctor
	
	//Set defaults so that the log manager is ready to go without needing setup
	m_pLogStream = &std::cout;
	m_iLoggingLevel = LL_NORMAL;
	
}

CLogMgr::~CLogMgr()
{
	//dtor
}

OutStream& CLogMgr::log(LogMessageLevel iLevel)
{
	assert(m_pLogStream);
	
	if (m_iLoggingLevel + iLevel > ODN_LOGGING_THRESHOLD) {
		
		//The log message level is such that it should be logged
		
		//Log the log message level
		*m_pLogStream << std::endl << "[" << iLevel << "]";
		
		//Return a reference to the log stream
		return *m_pLogStream;
		
	}
	else {
		
		//The log message level is such that it should not be logged
		
		//Flush the null stream
		m_NullStream.flush();
		
		//Return a reference to the null stream, so that writing to it
		// does nothing
		return m_NullStream;
		
	}
	
}

} //namespace ouden
